{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>adm_book</title>
{#    <link rel="stylesheet" href="{% static 'css/book.css' %}">#}
    <link rel="stylesheet" href="{% static 'css/sqlTable.css' %}">
    <link rel="stylesheet" href="{% static 'css/navbar.css' %}">
    <link rel="stylesheet" href="{% static 'css/pagination.css' %}">
    <link rel="stylesheet" href="{% static 'css/search.css' %}">
    <script type="text/javascript" src="{% static 'js/click.js' %}"></script>
</head>
<body>
<body background="{% static 'img/adm.jpg' %}" style="background-repeat:no-repeat ;background-size:100% 100%;background-attachment: fixed;">
    {% load static %}
    <!-- 导航栏 -->
    <div class="navbar">
        <div class="system-name">图书馆图书借阅系统——查看图书</div>
        <nav class="menu">
            <a href="/adm_index" class="menu-item">系统首页</a>
            <a href="/adm_book" class="menu-item">查看图书</a>
            <a href="/adm_borrow" class="menu-item">借阅记录</a>
            <a href="/adm_stuInfo" class="menu-item">学生信息</a>
            <a href="/adm_info" class="menu-item">个人中心</a>
        </nav>
        <div class="user-info">
            <span class="username">欢迎您，管理员：{{ adm_id }}</span>
            <a href="/login">
                <button class="button">退出</button>
            </a>
        </div>
    </div>

    <div class="search-bar">
        <form action="" method="post" name="search">
            {% csrf_token %}
            <input type="hidden" name="form_id" value="search">
            <input type="text" name="quest" placeholder="搜索图书...">
            <select id="category" name="category">
                <option value="book_name">书籍名</option>
                <option value="book_id">书籍号</option>
                <option value="book_author">作者</option>
                <option value="book_publisher">出版社</option>
            </select>
            <input type="submit" value="搜索">
        </form>
        <p>
        {% if quest and category %}
            {% if category == 'book_name' %}
                搜索方式：书籍名
                搜索内容：{{ quest }}
            {% elif category == 'book_author' %}
                搜索方式：作者
                搜索内容：{{ quest }}
            {% elif category == 'book_publisher' %}
                搜索方式：出版社
                搜索内容：{{ quest }}
            {% elif category == 'book_id' %}
                搜索方式：书籍号
                搜索内容：{{ quest }}
            {% endif %}
        {% endif %}
        </p>
        <p></p>
        <p style="color: red">
        {% if err %}
            {{ err }}
        {% endif %}
        </p>

    </div>

    <!-- 目录栏 -->
    <!-- 主内容区域 -->
    <div class= "container">
        <table>
            <thead>
                <tr>
                    <th>书籍图片</th>
                    <th>书籍号</th>
                    <th>书籍名</th>
                    <th>作者</th>
                    <th>出版社</th>
                    <th>书籍现存数量</th>
                    <th>选项</th>
                    <th>选项</th>
                </tr>
            </thead>
            <tbody>
                {% for book in book_queryset %}
                <tr>
                    <td><img src="{{ book.book_img }}" alt="图书图片" class="book-image"></td>
                    <td>{{ book.book_id }}</td>
                    <td>{{ book.book_name }}</td>
                    <td>{{ book.book_author }}</td>
                    <td>{{ book.book_publisher }}</td>
                    <td>{{ book.book_num }}</td>
                    <form method="post" action="/adm_bookInfo/">
                        {% csrf_token %}
                        <input type="hidden" name="form_id" value="check">
                        <input type="hidden" name="book_id" value="{{ book.book_id }}">
                        <td class="action-column">
                            <input type="submit" value="查看" class="tablebutton">
{#                            <button type="submit" value="查看">查看</button>#}
                        </td>
                    </form>
                    <form method="post" action="">
                        {% csrf_token %}
                        <input type="hidden" name="form_id" value="delete">
                        <input type="hidden" name="book_id" value="{{ book.book_id }}">
                        <td class="action-column">
                            <input type="submit" value="删除" class="tablebutton">
{#                            <button type="submit" value="删除">删除</button>#}
                        </td>
                    </form>
                </tr>
                {% endfor %}
            </tbody>
        </table>
        <div class="pagination">
            <form method="get" action=".">
                {% csrf_token %}
                {% if book_queryset.has_previous %}
                    <button type="submit" name="page" value="1">&laquo; 第一页</button>
                    <button type="submit" name="page" value="{{ book_queryset.previous_page_number }}">上一页</button>
                {% endif %}

                <span class="current">
                    页码 {{ book_queryset.number }} / {{ book_queryset.paginator.num_pages }}
                </span>

                {% if book_queryset.has_next %}
                    <button type="submit" name="page" value="{{ book_queryset.next_page_number }}">下一页</button>
                    <button type="submit" name="page" value="{{ book_queryset.paginator.num_pages }}">最后一页 &raquo;</button>
                {% endif %}
                {% if quest %}
                    <input type="hidden" name="quest" value="{{ quest }}">
                    <input type="hidden" name="category" value="{{ category }}">
                    <input type="hidden" name="form_id" value="search">
                {% endif %}
                </form>
        </div>

    </div>
    <p>
         <a href="/adm_bookAdd" class="belowButton_left">添加图书</a>
    </p>
    <form method="get" action="/export_to_excel/">
        <input type="hidden" name="quest" value="{{ quest }}">
        <input type="hidden" name="category" value="{{ category }}">
        <input type="hidden" name="exportId" value="book">
        <input type="submit" value="导出图书数据"  class="belowButton_right">
    </form>

</body>

</html>